home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / NUMBERS.SWG / 0012_HEX2BIN1.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  84 lines

  1. Function Hex2Bin (B : Byte) : String;
  2.  
  3. Var
  4.   Temp : String [8];
  5.   Pos, Mask : Byte;
  6.  
  7. begin
  8.   Temp := '00000000';
  9.   Pos := 8;
  10.   Mask := 1;
  11.   While (Pos > 0) Do
  12.     begin
  13.       if (B and Mask)
  14.         then
  15.           Temp [Pos] := '1';
  16.       Dec (Pos);
  17.       Mask := 2 * Mask;
  18.     end;
  19.   Hex2Bin := Temp;
  20. end;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. Function Hex2Bin( HexByte:Byte ):String; External; {$L HEX2Bin.OBJ}
  29. Var i : Integer;
  30. begin
  31.   For i := $00 to $0F do WriteLn( Hex2Bin(i) );
  32. end.
  33. (*********************************************************************)
  34.  
  35.  The Assembly source ...
  36.  
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38. code        segment Byte 'CODE'     ; HEX2Bin.Asm
  39.             assume  cs:code
  40. ; Function Hex2Bin( HexByte :Byte ) :String;
  41. String      equ     dWord ptr [bp+6]
  42. HexByte     equ     [bp+4]
  43.             public  Hex2Bin
  44. Hex2Bin     proc    Near            ; link into main TP Program
  45.             push    bp              ; preserve
  46.             mov     bp,sp           ; stack frame
  47.             les     di, String      ; result String Pointer
  48.             cld                     ; Forward scan
  49.             mov     cx,8            ; 8 bits in a Byte
  50.             mov     al,cl           ; to set
  51.             stosb                   ; binary String length
  52.             mov     ah, HexByte     ; get the hex Byte
  53.     h2b:    xor     al,al           ; cheap zero
  54.             rol     ax,1            ; high bit to low bit
  55.             or      al,'0'          ; make it ascii
  56.             stosb                   ; put it in String
  57.             loop    h2b             ; get all 8 bits
  58.             pop     bp              ; restore
  59.             ret     2               ; purge stack & return
  60. Hex2Bin     endp
  61. code        ends
  62.             end
  63. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  64.  
  65.  Here's the assembled OBJ File ...
  66.  
  67.  Put all of this remaining message in a Text File named HEX2Bin.SCR,
  68.  then Type "DEBUG < HEX2Bin.SCR" (no quotes) to create HEX2Bin.ARC;
  69.  then extract HEX2Bin.OBJ using PKUNPAK or PAK ...
  70.  ---------------------------- DEBUG script ----------------------------
  71.  N HEX2Bin.ARC
  72.  E 0100 1A 02 48 45 58 32 42 49 4E 2E 4F 42 4A 00 5E 65 00 00 00 4A 19
  73.  E 0115 13 22 60 F2 65 00 00 00 80 0D 00 0B 68 65 78 32 62 69 6E 2E 41
  74.  E 012A 53 4D A9 96 07 00 00 04 43 4F 44 45 44 98 07 00 20 1D 00 02 02
  75.  E 013F 01 1F 90 0E 00 00 01 07 48 45 58 32 42 49 4E 00 00 00 6A 88 04
  76.  E 0154 00 00 A2 01 D1 A0 21 00 01 00 00 55 8B EC C4 7E 06 FC B9 08 00
  77.  E 0169 8A C1 AA 8A 66 04 32 C0 D1 C0 0C 30 AA E2 F7 5D C2 02 00 21 8A
  78.  E 017E 02 00 00 74 1A 00
  79.  Rcx
  80.  0084
  81.  W
  82.  Q
  83.  ----------------------------------------------------------gbug-1.0b--
  84.